package com.zhuoyue.biz.core.command.impl.panel;

import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zhuoyue.biz.core.command.CmdParams;
import com.zhuoyue.biz.core.command.model.PanelCmd;
import com.zhuoyue.common.utils.CmdUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * 三路联控面板控制类
 *
 * @author Administrator
 */
public class ThreeWayJointControlPanel0Faa0704 {

    public static String getCommand(String controlParam) {
        Map<String, String> map = (Map) JSONObject.parse(controlParam);

        String controlType = map.get("controlType");
        if (StringUtils.isEmpty(controlType)) {
            return null;
        }

        String cmd = "";
        if (CmdParams.ControlType.CONTROL_TYPE_DIRECT.equals(controlType)) {
            cmd = getDirectControlCmd(map);
        }

        return cmd;
    }


    private static String getDirectControlCmd(Map<String, String> map) {

        Map<String, String> actionsMap = (Map) JSONObject.parse(JSON.toJSONString(map.get("actions")));

        String wayNumber = actionsMap.get("wayNumber");
        String controlState = CmdUtils.intToHexTwo(Integer.parseInt(actionsMap.get("controlState")));

        if (CmdParams.Panel.WAY_1.equals(wayNumber)) {
            return new PanelCmd(map.get("gatewayMac"), map.get("deviceMac"), CmdParams.Od0Faa.WAY_1, controlState).getCmd(CmdParams.CmdModel.PANEL_0FAA);
        } else if (CmdParams.Panel.WAY_2.equals(wayNumber)) {
            return new PanelCmd(map.get("gatewayMac"), map.get("deviceMac"), CmdParams.Od0Faa.WAY_2, controlState).getCmd(CmdParams.CmdModel.PANEL_0FAA);
        } else if (CmdParams.Panel.WAY_3.equals(wayNumber)) {
            return new PanelCmd(map.get("gatewayMac"), map.get("deviceMac"), CmdParams.Od0Faa.WAY_3, controlState).getCmd(CmdParams.CmdModel.PANEL_0FAA);
        }
        return null;
    }
}
